<?php
#-------------------------------------------------------------------------
# Module: Counters
# Version: 1.0, Jo Morg
# Method: Default Action
#-------------------------------------------------------------------------
# CMS - CMS Made Simple is (c) 2008 by Ted Kulp (wishy@cmsmadesimple.org)
# This project's homepage is: http://www.cmsmadesimple.org
# The module's homepage is: http://dev.cmsmadesimple.org/projects/skeleton/
#
#-------------------------------------------------------------------------
if(!is_object(@cmsms()))exit;

// get our records from the database
$db = $gCms->GetDb();
#$smarty = cmsms()->GetSmarty();

$query = 'SELECT * from ' . cms_db_prefix() . 'module_counters';

if (isset($params['counter_id']))
{
    $query .= ' where cntr_id = ?';
    $result = $db->Execute($query,array($params['counter_id']));
}
elseif (isset($params['name']))
{
    $query .= ' where name = ?';
    $result = $db->Execute($query,array($params['name']));
}
else
{
    // put mention into the admin log
    $this->Audit( 0, 
          $this->Lang('friendlyname'), 'Insuficient tag parameters: at least one (name or counter_id) required.');
    return;
}

if ($result !== false && $row = $result->FetchRow())
{                    
    if (isset($params['ceiling']))
    {
        #$smarty->assign($params['ceiling'],$row['ceiling']);    
        $this->smarty->assign($params['ceiling'], $row['ceiling']);    
    }
    else
    {
        #$smarty->assign('ceiling', $row['ceiling']);   
        $this->smarty->assign('ceiling', $row['ceiling']);   
    }
    
    
        if (isset($params['value']))
    {
        #$smarty->assign($params['value'], $row['value']);      
        $this->smarty->assign($params['value'], $row['value']);      
    }
    else
    {
        #$smarty->assign('value', $row['value']);      
        $this->smarty->assign('value', $row['value']);      
    } 
    
    #debug
    #echo ( $row['value'] );   
}
else
{
    // put mention into the admin log
    $this->Audit( 0, 
          $this->Lang('friendlyname'), 'Requested counter doesnt exist in DB.');
}
?>